package com.joyoung.datarespository;


import com.joyoung.cons.Cons;

import org.json.JSONObject;

/**
 * Created by Administrator on 2017\8\3 0003.
 */

public class FreeStyleBuilder {

    private JSONObject jsonObject = new JSONObject();
    private JSONObject data = new JSONObject();
    private JSONObject mob_data = new JSONObject();
    private JSONObject getui = new JSONObject();

    private boolean hasData = false;

    public FreeStyleBuilder action(String action) throws Exception {
        jsonObject.put("op_action", action);
        jsonObject.put("sessionkey", Cons.sessionkey);
        return this;
    }

    public FreeStyleBuilder version(String version) throws Exception{
        jsonObject.put("api_version", version);
        return this;
    }

    public FreeStyleBuilder mobilenum(String mobilenum) throws Exception{
        jsonObject.put("mobilenum", mobilenum);
        return this;
    }

    public  FreeStyleBuilder cid(String cid) throws Exception{
        getui.put("cid",cid);
        jsonObject.put("getui", getui);
        return this;
    }



    public FreeStyleBuilder uname(String uname) throws Exception{
        jsonObject.put("uname", uname);
        return this;
    }

    public FreeStyleBuilder type(int type) throws Exception{
        jsonObject.put("type", type);
        return this;
    }

    public FreeStyleBuilder sortby(String sortby) throws Exception{
        jsonObject.put("sortby", sortby);
        return this;
    }


    public FreeStyleBuilder actid(String actid) throws Exception{
        jsonObject.put("actid", actid);
        return this;
    }

    public FreeStyleBuilder sn(String sn) throws Exception{
        jsonObject.put("sn", sn);
        return this;
    }


    public FreeStyleBuilder menuid(String menuid) throws Exception{
        jsonObject.put("menuid", menuid);
        return this;
    }

    public FreeStyleBuilder mdcode(String mdcode) throws Exception{
        data.put("mdcode", mdcode);
        hasData = true;
        return this;
    }

    public FreeStyleBuilder client(String client) throws Exception{
        data.put("client", client);
        hasData = true;
        return this;
    }

    public FreeStyleBuilder mobile_id(String mobile_id) throws Exception{
        mob_data.put("mobile_id", mobile_id);
        jsonObject.put("mob_data", mob_data);

        return this;
    }

    public FreeStyleBuilder version_data(String version) throws Exception{
        data.put("version", version);
        hasData = true;
        return this;
    }
    public FreeStyleBuilder mdtime(String mdtime) throws Exception{
        data.put("mdtime", mdtime);
        hasData = true;
        return this;
    }

    public FreeStyleBuilder page(int start,int limit) throws Exception{
        JSONObject page = new JSONObject();
        page.put("start", start);
        page.put("limit", limit);
        jsonObject.put("page", page);
        return this;
    }

    public FreeStyleBuilder system(String system) throws Exception{
        data.put("system", system);
        hasData = true;
        return this;
    }


    public String build() throws Exception {
        if(hasData){
            jsonObject.put("data",data);
        }
        return jsonObject.toString();
    }

}
